package com.wjggy;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.Logger;

import com.wjggy.core.common.util.preferences.ConfigKeys;
import com.wjggy.core.common.util.preferences.SystemGlobals;

public class WjggyBaseServlet extends HttpServlet{
	private static final Logger logger = Logger.getLogger(WjggyBaseServlet.class);
	/**
	 * 启动运用程序
	 */  
	protected void startApplication(){
		try { 
			String classesPath = this.getClass().getClassLoader().getResource("").getPath();
			logger.info("=============Constant.getPorjectPath()="+classesPath);
			String photoPath = classesPath + "virtualdir/upload/data/photo/fmcg/";
			logger.info("=============photoPath="+photoPath);

			
			
			ServletContext application=this.getServletContext(); 
			String mainConfigurationFile=this.getServletConfig().getInitParameter(ConfigKeys.INITCONFIG_KEY);
			String appPath=application.getRealPath("");
			SystemGlobals.initGlobals(appPath,appPath+"/WEB-INF/config/"+ mainConfigurationFile);
			application.setAttribute("stylePath", SystemGlobals.getValue("stylePath"));
			application.setAttribute("jsPath", SystemGlobals.getValue("jsPath"));
			application.setAttribute("imagesPath", SystemGlobals.getValue("imagesPath"));
			application.setAttribute("webName",SystemGlobals.getValue(ConfigKeys.WEB_NAME));
		} catch (RuntimeException e) {
			e.printStackTrace();
			logger.error("加载配置文件失败", e);
		}
	}
}
